import { defineStore } from "pinia";
import request from '../utils/request.js'
export const useStar = defineStore('star',{
  state:()=>{
    return {
      list:[]
    }
  },
  actions:{
    async initStarList(){  //异步actions
      let res = await request.get('/star')
      console.log(res);
      this.list = res.data.data
    },
    async starPost(payload){
      let res = await request.post('/star',payload) //更新数据库
      console.log(res);
      if(res.data.code==1){
        this.list.push(payload) //更新本地
      }
    }
  },
  getters:{ //相当于组件中的computed作用
    filterList(){
      let arr = this.list.filter(item=>{
        return item.age>=30
      })
      return arr
    }
  }
})